#pragma once

#include "fm33le0xx_fl.h"

typedef struct {
    uint8_t hardware_product_id;    // 硬件厂商代码
    uint8_t product_id;             // 产品型号
    uint8_t hardware_version;       // 硬件版本序号
    uint8_t reserved1;              //
    uint8_t soft_version_minor;     // 次软件版本号
    uint8_t soft_version_major;     // 主软件版本号
    uint8_t boot_verion;            // BOOT底层软件版本
    uint8_t boot_update_version;    // BOOT升级协议版本
    uint8_t com_version_minor;      // 次通讯协议版本
    uint8_t com_version_major;      // 主通讯协议版本
    uint8_t reserved2[6];           // 
} __attribute__ ((packed)) k_initial_data_t;

typedef struct {
    struct {
        uint8_t year;
        uint8_t mon;
        uint8_t day;
        uint8_t hour;
        uint8_t min;
        uint8_t sec;
        /* data */
    } time;
    
    uint8_t time_show_enable: 1;
    uint8_t gsm: 1;
    uint8_t gps: 1;
    uint8_t zero_odo: 2;
    uint8_t reserved1: 3;

    uint8_t head_lock: 3;
    uint8_t head_lock_motor_error: 2;
    uint8_t seat_lock: 3;

    uint8_t remaining_mileage_show: 2;
    uint8_t poweroff_time_show: 2;
    uint8_t auto_head_light: 2;
    uint8_t head_lock_latch_tongue_error: 2;

    uint8_t bat_percent;

    uint8_t alarm_status: 4;
    uint8_t reserved2: 4;

    uint8_t remaining_mileage_value;
    
    uint8_t reserved3[4];
} __attribute__ ((packed)) k_bcm_message_t;

typedef struct {
    uint16_t speed;
    uint16_t trip;

    uint8_t zero_odo_status: 3;
    uint8_t remaining_mileage_show_status: 2;
    uint8_t auto_head_light_status: 2;
    uint8_t reserved: 1;

    uint32_t odo;

    uint8_t bat_small_status: 3;
    uint8_t reserved1: 5;

    uint8_t reserved2[6];
} __attribute__ ((packed)) k_bcm_reply_message_t;

typedef void(*k_frame_recv_cb_t)(int cmd, const uint8_t* buf, int len);

void k_line_init(k_frame_recv_cb_t recv_cb);

void k_line_deal_rx_fifo_data();

void k_line_write_bytes(uint16_t cmd, const uint8_t* frame, uint32_t len);
